home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 23 / AACD 23.iso / AACD / Online / opennap / announce.c < prev    next >
C/C++ Source or Header  |  2001-06-08  |  3KB  |  132 lines

  1. /* Copyright (C) 2000-1 drscholl@users.sourceforge.net
  2.    This is free software distributed under the terms of the
  3.    GNU Public License.  See the file COPYING for details.
  4.  
  5.    $Id: announce.c,v 1.22 2001/02/15 08:39:45 drscholl Exp $ */
  6.  
  7. #ifndef WIN32
  8. #include <unistd.h>
  9. #endif /* !WIN32 */
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include <stdlib.h>
  13. #include "opennap.h"
  14. #include "debug.h"
  15.  
  16. /* called when receiving a global message */
  17. /* 627 [ <nick> ] <message> */
  18. HANDLER (announce)
  19. {
  20.     USER   *user;
  21.  
  22.     (void) tag;
  23.     (void) len;
  24.     ASSERT (validate_connection (con));
  25.  
  26.     if (ISUSER (con))
  27.     user = con->user;
  28.     else
  29.     {
  30.     char   *ptr;
  31.  
  32.     ASSERT (ISSERVER (con));
  33.     ptr = next_arg_noskip (&pkt);
  34.     if (!pkt)
  35.     {
  36.         log ("announce: too few arguments in server message");
  37.         return;
  38.     }
  39.     user = hash_lookup (Users, ptr);
  40.     if (!user)
  41.     {
  42.         log ("announce: can't find user %s", ptr);
  43.         return;
  44.     }
  45.     }
  46.  
  47.     ASSERT (validate_user (user));
  48.  
  49.     /* check to see that the user has privileges */
  50.     if (user->level < LEVEL_ADMIN)
  51.     {
  52.     log ("announce: %s is not admin", user->nick);
  53.     if (ISUSER (con))
  54.         permission_denied (con);
  55.     return;
  56.     }
  57.  
  58.     send_all_clients (tag, "%s %s",
  59.               user->cloaked ? "Operator" : user->nick, pkt);
  60.  
  61.     /* pass the message to our peer servers if a local user sent it */
  62.     pass_message_args (con, tag, "%s %s",
  63.                user->cloaked ? "Operator" : user->nick, pkt);
  64. }
  65.  
  66. /* 628 [ <nick> ] <message> */
  67. /* send a message to all mods+ */
  68. HANDLER (wallop)
  69. {
  70.     char   *ptr;
  71.     int     l;
  72.     LIST   *list;
  73.     CONNECTION *c;
  74.  
  75.     (void) tag;
  76.     (void) len;
  77.     ASSERT (validate_connection (con));
  78.     if (con->class == CLASS_USER)
  79.     {
  80.     ASSERT (validate_user (con->user));
  81.     if (con->user->level < LEVEL_MODERATOR)
  82.     {
  83.         permission_denied (con);
  84.         return;
  85.     }
  86.     ptr = con->user->nick;
  87.     }
  88.     else
  89.     {
  90.     ptr = next_arg_noskip (&pkt);
  91.     if (!pkt)
  92.     {
  93.         log ("wallop: malformed message from %s", pkt);
  94.         return;
  95.     }
  96.     }
  97.  
  98.     l = form_message (Buf, sizeof (Buf), tag, "%s %s", ptr, pkt);
  99.     pass_message (con, Buf, l);
  100.  
  101.     for (list = Mods; list; list = list->next)
  102.     {
  103.     c = list->data;
  104.     if (c->uopt->usermode & WALLOPLOG_MODE)
  105.         queue_data (c, Buf, l);
  106.     }
  107. }
  108.  
  109. /* 10021 :<server> <loglevel> "<message>" */
  110. HANDLER (remote_notify_mods)
  111. {
  112.     int     ac, level;
  113.     char   *av[3];
  114.  
  115.     (void) len;
  116.     if (*pkt != ':')
  117.     {
  118.     log ("remote_notify_mods: missing server name");
  119.     return;
  120.     }
  121.     ac = split_line (av, FIELDS (av), pkt);
  122.     if (ac < 3)
  123.     {
  124.     log ("remote_notify_mods: too few parameters");
  125.     print_args (ac, av);
  126.     return;
  127.     }
  128.     level = atoi (av[1]);
  129.     notify_mods (level, "[%s] %s", av[0] + 1, av[2]);
  130.     pass_message_args (con, tag, ":%s %d \"%s\"", av[0] + 1, level, av[2]);
  131. }
  132.